<%@ language="javascript" %>
<%

/*
	Sample ASP script to save an uploaded image
	This script saves the uploaded file in a folder corresponding to the file's folder attribute.
	This is entirely optional.  The script could just as well save all uploaded files in one
	and the same directory, and save the folder location to a database, so a virtual folder
	list can be built for the end user.
	
	The name attribute isn't used in this sample, but could conceivably be used to save a more
	meaningful description of a file to a database.
	
	The http response is an xml string containing the uploaded file's url.
	This is necesarry, as the editor has no other way to know which hyperlink it should generate.
*/

var doc = new ActiveXObject( 'Msxml2.DomDocument' );
doc.load( Request );

var elt = doc.selectSingleNode( 'root/file' );
var href = elt.getAttribute( 'href' );
href = href.replace( /.*[\\\/](.*)/, '$1' );

var folder = '/';
folder += elt.getAttribute( 'folder' );

var name = elt.getAttribute( 'name' );

var str = new ActiveXObject( 'Adodb.Stream' );
str.type = 1;
str.open();
str.write( elt.nodeTypedValue );
//str.saveToFile( 'c:/wwwroot' + folder + href, 2 );
str.close();

Response.contentType = 'text/xml';
Response.write( '<root><file href="/upload' + folder + href + '"/></root>' );

str = null;
doc = null;
%>